package org.weed.remote.ui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.io.File;

import javax.media.Manager;
import javax.media.Player;
import javax.swing.JPanel;

public class MediaPanel extends JPanel {
	private Player player;
	public MediaPanel() {
		setLayout(new BorderLayout());
		Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
	}

	public void open(File file) {
		try {
			player = Manager.createPlayer(file.toURL());
			Component video = player.getVisualComponent();
			Component controls = player.getControlPanelComponent();
			if (video != null) {
				add(video, BorderLayout.CENTER);
			}
			if (controls != null) {
				add(controls, BorderLayout.CENTER);
			}
		} catch (Exception e) {
			//System.err.println("Can't open file [" + file.getAbsolutePath() + "]");
			e.printStackTrace();
		}
	}
	
	public void start() {
		try {
			player.start();
		} catch (Exception e) {
			
		}
	}
}
